package com.liuwei.consultant.controller;

import com.liuwei.consultant.aiservice.ConsultantService;
import dev.langchain4j.model.openai.OpenAiChatModel;
import dev.langchain4j.store.memory.chat.ChatMemoryStore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@RestController
public class ChatController {

    @Autowired
    private OpenAiChatModel model;

    @Autowired
    private ConsultantService consultantService;


    // 直接使用OpenAiChatModel调用
    @RequestMapping("/chat1")
    public String chat1(String message) {
        String result = model.chat(message);
        return result;
    }

    // 使用AiService调用
    /*@RequestMapping("/chat2")
    public String chat2(String message) {
        String result = consultantService.chat(message);
        return result;
    }*/

    // 使用AiService流式调用
    @RequestMapping(value = "/chat",produces = "text/html;charset=utf-8")
    public Flux<String> chat3(String memoryId, String message) {
        Flux<String> result = consultantService.chat(memoryId, message);
        return result;
    }
}
